package com.tt.vtg.scenario.util.json;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;

public class JsonUtils {
    private JsonUtils(){}
    private static ObjectMapper objMap = new ObjectMapper();

    public static String toJson(Object o) {
        try {
            return objMap.writeValueAsString(o);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static <T> T toObj(String jsonStr, Class<T> clz){
        try {
            return objMap.readValue(jsonStr, clz);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
